//
//  LoadMoreViewController.m
//  firstpoint
//
//  Created by 泽中 on 2017/6/29.
//  Copyright © 2017年 xzcysoft. All rights reserved.
//

#import "LoadMoreViewController.h"
#import "RenWuTableViewCell.h"
#import "RenWuXiangQingViewController.h"
@interface LoadMoreViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView*tabView;
    int page;
}
@property(nonatomic,strong)NSMutableArray *bigMUArr;
@end

@implementation LoadMoreViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"加载更多";
    self.view.backgroundColor=[UIColor whiteColor];
    page=1;
    _bigMUArr = [NSMutableArray array];
    [self setTab];
    [self httpjiazaiRenwuUrl];//全部任务

    
}
-(void)setTab
{
    tabView=[[UITableView alloc]initWithFrame:CGRectMake(0, 64, width_screen, height_screen-64) style:1];
    tabView.separatorStyle=0;
    tabView.delegate=self;
    //    tabView.mj_header
    tabView.dataSource=self;
    [tabView registerClass:[RenWuTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:tabView];
    //上拉加载
    __weak typeof(self) waekSelf = self;
    MJRefreshAutoGifFooter *footer = [MJRefreshAutoGifFooter footerWithRefreshingBlock:^{
        page++;
        [waekSelf httpjiazaiRenwuUrl];
    }];
    [HTTPURL MJfoodDH:footer];
    tabView.mj_footer = footer;
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _bigMUArr.count;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 40;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    RenWuTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (_bigMUArr.count>1) {
        cell.titleLab.text = [NSString stringWithFormat:@"%@",_bigMUArr[indexPath.row][@"title"]];//b标题
        cell.infoLab.text = [NSString stringWithFormat:@"%@",_bigMUArr[indexPath.row][@"description"]];//内容
        cell.jindouLab.text = [NSString stringWithFormat:@"%@ 金豆",_bigMUArr[indexPath.row][@"otayonii"]];//金豆
        cell.youxiajiaoLab.text = [NSString stringWithFormat:@"参与 %@",_bigMUArr[indexPath.row][@"counts"]];//参与
    }
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    RenWuXiangQingViewController*vc=[RenWuXiangQingViewController new];
    vc.idString = _bigMUArr[indexPath.row][@"id"];
    vc.hidesBottomBarWhenPushed=YES;
    [self.navigationController pushViewController:vc animated:YES];
}
//任务加载更多请求
-(void)httpjiazaiRenwuUrl{
    NSLog(@"%@",CIT_number);
    NSString *nub = [NSString stringWithFormat:@"%@",CIT_number];
    NSString *url = [NSString stringWithFormat:@"%@%@",LINK_BASE_URL(@"task/taskAllList.api?access_token="),NSUD_Obj(@"token")];
    [HTTPURL postRequest:url parameters:@{@"pageIndex":@(page),@"areaId":nub} success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSLog(@"%@",responseObject);
        if ([responseObject[@"retFlag"]integerValue]==1) {
            NSDictionary *dic = [PublicTools dictionaryWithJsonString:responseObject[@"data"]];
            NSArray *array = [NSArray array];
            array = dic[@"rows"];
            [_bigMUArr addObjectsFromArray:array];
            [tabView reloadData];
            [tabView.mj_footer endRefreshing];
        }
        
    } filure:^(NSURLSessionDataTask *task, id error) {
        NSLog(@"%@",error);
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
